from matplotlib import pyplot as plt
import numpy as np
from openpyxl import load_workbook

wb = load_workbook('./数据生成算法实验.xlsx')
sheet = wb['带权重采样']

weights = []
for r in range(2, 139):
    w = sheet.cell(row=r, column=12).value
    if w is not None:
        w = eval(w)
        weights.append(w)

analysis = np.asarray(weights)

max_matrix = np.max(analysis, 0)
mean_matrix = np.mean(analysis, 0)

# print(max_matrix)
# print(mean_matrix)
for x in mean_matrix:
    print(x)

# x = np.arange(1, 43, 1)
#
# bar_width = 0.4
#
# plt.title('Average/Maximum Effectiveness of Mutation Methods')
# plt.bar(x=x+bar_width, width=bar_width, label='Maximum Effectiveness', height=max_matrix)
# plt.bar(x=x, width=bar_width, label='Average Effectiveness', height=mean_matrix)
#
# for x_, y_ in enumerate(mean_matrix.tolist()):
#      if y_ >= 0.9:
#           plt.text(x_ - 800, y_ - bar_width / 2, '{0}'.format(x_), ha='center', va='bottom', fontsize=7)
#      else:
#           plt.text(x_ + 800, y_ - bar_width / 2, '{0}'.format(x_), ha='center', va='bottom', fontsize=7)
#
# for x_, y_ in enumerate(max_matrix.tolist()):
#      if y_ >= 0.9:
#           plt.text(x_ - 800, y_ + bar_width / 2, '{0}'.format(x_), ha='center', va='bottom', fontsize=7)
#      else:
#           plt.text(x_ + 800, y_ + bar_width / 2, '{0}'.format(x_), ha='center', va='bottom', fontsize=7)
#
# plt.xlabel("Mutation Method(s)",fontsize=7)
# plt.ylabel("Effectiveness",fontsize=7)
# plt.xticks(np.arange(len(x))+bar_width/2, x, fontsize=6)
# plt.yticks(fontsize=7)
# plt.legend(loc='upper center', fontsize=8)
#
# plt.show()